package com.xbongbong.paas.statistics.model.impl;

import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.paas.domain.dao.PaasAggRuleDao;
import com.xbongbong.paas.domain.entity.PaasAggRuleEntity;
import com.xbongbong.paas.statistics.model.AggRuleModel;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 创建时间： 2018/9/11 11:30
 * 修改时间： 2018/9/11 11:30 梁鲁江
 *
 * @author 梁鲁江
 */
@Service("aggRuleMode")
public class AggRuleModelImpl implements AggRuleModel {
    @Resource
    private PaasAggRuleDao paasAggRuleDao;
    @Override
    public Integer insert(PaasAggRuleEntity entity) {
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return paasAggRuleDao.insert(entity);
    }
    @Override
    public Integer update(PaasAggRuleEntity entity) {
        entity.setUpdateTime((long) DateUtil.getInt());
        return paasAggRuleDao.update(entity);
    }

    @Override
    public Integer save(PaasAggRuleEntity entity) {
        if(entity.getId() == null || entity.getId().equals(0L)) {
            return insert(entity);
        }
        return update(entity);
    }

    @Override
    public List<PaasAggRuleEntity> list(Map<String, Object> params) {
        return paasAggRuleDao.findEntitys(params);
    }

    @Override
    public PaasAggRuleEntity getByKey(Long key, String corpid) {
        return paasAggRuleDao.getByKey(key, corpid);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> params) {
        return paasAggRuleDao.getEntitysCount(params);
    }

    @Override
    public Integer delete(Long key, String corpid) {
        return paasAggRuleDao.deleteByKey(key, corpid);
    }
}
